package com.example.easyscript.controller.task;

import com.example.easyscript.entity.task.Entrance;
import com.example.easyscript.entity.task.Operation;
import com.example.easyscript.entity.task.Status;
import com.example.easyscript.service.task.OperationService;
import com.example.easyscript.service.task.TaskLoader;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author huzixian
 * @date 2023-03-08
 */
@Api(value = "OperationController", tags = "")
@Slf4j
@RestController
@RequestMapping(value = "/web/operation")
public class OperationController {

    @Resource
    private OperationService operationService;

    @ApiOperation("新增状态")
    @PostMapping("/save")
    public void save(@RequestBody Operation operation) {
        Integer order = TaskLoader.getMaxOrder(operationService, operation.getTaskId());
        operation.setOrderId(order + 1);
        operationService.save(operation);
    }

    @ApiOperation("获取对应任务的状态集")
    @GetMapping("/getList/{taskId}")
    public List<Operation> getList(@PathVariable Integer taskId) {
        return TaskLoader.loadEntityListByTaskId(taskId,operationService, Operation.class);
    }

}